/**
 * 
 */
package com.changil.nowonchangilchurch.ui.item;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.changil.nowonchangilchurch.R;
import com.changil.nowonchangilchurch.util.UrlUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * @author 홍창우
 *
 */
public class ArticleImageItem extends RelativeLayout {

	private RelativeLayout mLayout = null;
	private ImageView mContentImage = null;
	
	/**
	 * @param context
	 */
	public ArticleImageItem(Context context) {
		super(context);
		init(context);
	}

	/**
	 * @param context
	 * @param attrs
	 */
	public ArticleImageItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	/**
	 * @param context
	 * @param attrs
	 * @param defStyle
	 */
	public ArticleImageItem(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}
	
	private void init(Context context) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mLayout = (RelativeLayout) inflater.inflate(R.layout.article_image_item, this, true);
		mContentImage = (ImageView)mLayout.findViewById(R.id.article_image_item_image);
	}
	
	
	public void setContentImage(ImageLoader imageLoader, String url, int width,DisplayImageOptions options) {
		if(null != url && null == mContentImage.getDrawable()) {
			imageLoader.displayImage(UrlUtil.getThumbnailUrl(url, width), mContentImage, options, null);
		}
	}
}
